package src.Fourteen;

import javax.swing.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;

public class WindowFocusListener_Example extends JFrame {

    public static void main(String[] args) {
        WindowFocusListener_Example example = new WindowFocusListener_Example();
        example.setVisible(true);
    }

    public WindowFocusListener_Example(){
        super();
        addWindowFocusListener(new MyWindowFocusListener());
        setTitle("捕获窗体焦点事件");
        setBounds(100,100,500,375);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    private class MyWindowFocusListener implements WindowFocusListener{

        @Override
        public void windowGainedFocus(WindowEvent e) {
            System.out.println("窗口获得了焦点");
        }

        @Override
        public void windowLostFocus(WindowEvent e) {
            System.out.println("窗口失去了焦点");
        }
    }
}
